//
//  MineAccountViewController.swift
//  FrameProduct
//
//  Created by delegate on 2025/10/22.
//

import UIKit

class MineAccountViewController: BaseViewController {
    var dataSourceArr: [MineModel] = [MineModel]()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupNavi()
        setupUI()
        
    }
    private func setupNavi() {
        navigationItem.title = "个人中心"
    }
    private func setupUI() {
        view.addSubviews(oneBgView, twobgView, loginButton)
        oneBgView.addSubviews(userNameView, updatePasswordView)
        twobgView.addSubviews(phoneBindView, emailBindView)
        
        oneBgView.snp.makeConstraints { make in
            make.top.equalTo(30)
            make.left.equalTo(13)
            make.right.equalTo(-13)
            make.height.equalTo(112)
        }
        twobgView.snp.makeConstraints { make in
            make.top.equalTo(oneBgView.snp.bottom).offset(12)
            make.left.equalTo(13)
            make.right.equalTo(-13)
            make.height.equalTo(112)
        }
        
        loginButton.snp.makeConstraints { make in
            make.top.equalTo(twobgView.snp.bottom).offset(48)
            make.left.equalTo(22)
            make.right.equalTo(-22)
            make.height.equalTo(50)
        }
        
        userNameView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
        }
        updatePasswordView.snp.makeConstraints { make in
            make.top.equalTo(userNameView.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(userNameView.snp.height)
            make.bottom.equalToSuperview()
        }
        phoneBindView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
        }
        emailBindView.snp.makeConstraints { make in
            make.top.equalTo(phoneBindView.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(phoneBindView.snp.height)
            make.bottom.equalToSuperview()
        }
    }
    private func didTapAction(_ type: Int) {
        switch type {
        case 0:
            //复制
            if userNameView.subTitleStr.isEmpty { return }
            let board = UIPasteboard.general
            board.string = userNameView.subTitleStr
            Toast.with(message: "复制成功").showOnWindow()
        case 1:
            let vc = MineUpdatePasswordViewController()
            navigationController?.pushViewController(vc, animated: true)
        case 2:
            let vc = MineBindViewController()
            vc.isPhone = true
            navigationController?.pushViewController(vc, animated: true)
        case 3:
            let vc = MineBindViewController()
            vc.isPhone = false
            navigationController?.pushViewController(vc, animated: true)
        default:
            break
        }
    }
    //=================================================================
    //                            lazy
    //=================================================================
    // MARK: - lazy
    private lazy var loginButton: UIButton = {
        let button = UIButton(type: .custom)
        button.setBackgroundImage(UIImage(named: "login_bg_img"), for: .normal)
        button.setBackgroundImage(UIImage(named: "login_bg_img"), for: .normal)
        button.setTitle("登录", for: .normal)
        button.setTitle("登录", for: .selected)
        button.setTitleColor(.lxs.hex("#F7FAFF"), for: .normal)
        button.setTitleColor(.lxs.hex("#F7FAFF"), for: .selected)
        button.titleLabel?.font = .lxs.font(size: 16)
//        button.addTarget(self, action: #selector(loginButtonAction), for: .touchUpInside)
        return button
    }()
    private lazy var twobgView: UIView = {
        let view = UIView()
        view.backgroundColor = .lxs.hex("#152443")
        view.layer.cornerRadius = 10
        view.layer.masksToBounds = true
        return view
    }()
    private lazy var oneBgView: UIView = {
        let view = UIView()
        view.backgroundColor = .lxs.hex("#152443")
        view.layer.cornerRadius = 10
        view.layer.masksToBounds = true
        return view
    }()
    private lazy var userNameView: MineAccountTableViewCell = {
        let view = MineAccountTableViewCell()
        view.titleStr = "用户名"
        view.subTitleStr = ""
        view.arrowIconStr = "mine_account_copy_icon"
        view.mineAccountViewDidTapActionBlock = {[weak self] in
            self?.didTapAction(0)
        }
        return view
    }()
    private lazy var updatePasswordView: MineAccountTableViewCell = {
        let view = MineAccountTableViewCell()
        view.titleStr = "修改密码"
        view.subTitleStr = ""
        view.mineAccountViewDidTapActionBlock = {[weak self] in
            self?.didTapAction(1)
        }
        return view
    }()
    private lazy var phoneBindView: MineAccountTableViewCell = {
        let view = MineAccountTableViewCell()
        view.titleStr = "手机"
        view.subTitleStr = "暂未绑定"
        view.mineAccountViewDidTapActionBlock = {[weak self] in
            self?.didTapAction(2)
        }
        return view
    }()
    private lazy var emailBindView: MineAccountTableViewCell = {
        let view = MineAccountTableViewCell()
        view.titleStr = "邮箱"
        view.subTitleStr = "暂未绑定"
        view.mineAccountViewDidTapActionBlock = {[weak self] in
            self?.didTapAction(3)
        }
        return view
    }()
}

